package org.third.integration.hibernate;

import com.fasterxml.jackson.core.JsonProcessingException;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.third.common.StringUtil;

import java.io.Serializable;
import java.util.List;


public class HibernateTet implements Serializable {
    private String user = "sadf";

    public String getUser() {
        return user;
    }

    public static void main(String[] args) throws JsonProcessingException {

        String a = StringUtil.toString(new HibernateTet());
        System.out.println(a);
        
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/org/third/hibernate/Hibernate_Spring.xml");
        SessionFactory sf = (SessionFactory) ctx.getBean("sessionFactory");
        org.hibernate.Session s = sf.openSession();
        // cannot define positional parameter after any named parameters have been defined 
        Query q = s.createQuery("from Organization where name=? type=:type").setString(0 , "Provider").setString("type", "PROVIDER");
        List ql = q.list();
        System.out.println(ql);
        System.out.println("--------------------");
//        Criteria c = s.createCriteria(Organization.class).setFetchMode(a, FetchMode.JOIN).add(Restrictions.eq("name", "Provider"));
//        List cl=c.list();
//        System.out.println(cl);
        
        
    }
}
